package com.liang.treemap;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {


        TreeMap<Student, String> tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge()-o2.getAge();
                return result == 0? o1.getName().compareTo(o2.getName()):result;
            }
        });

        Student stu1 = new Student("xiaomei", 23);
        Student stu2 = new Student("dapang", 24);
        Student stu3 = new Student("zongye", 22);
        Student stu4 = new Student("meizhi", 22);

        tm.put(stu1, "北京");
        tm.put(stu2, "上海");
        tm.put(stu3, "河北");
        tm.put(stu4, "天津");

        tm.forEach((key,value)->{
            System.out.println(key+"----"+value);
        });
    }
}
